package com.sgb.kjwl.viewmodel.manage;

import android.app.Activity;

import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.manage.WebsiteInfoEntity;
import com.sgb.kjwl.repository.ManageRepertory;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteMyXiXinActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 张驰
 * @date 2021/6/3 18:04
 * @Description 个人网站简介详情界面Model
 * @name com.sgb.kjwl.viewmodel.manage
 */
public class WebsiteMyXiXinModel extends BaseViewModel {


    private WebsiteMyXiXinActivity websiteMyXiXinActivity;
    private ManageRepertory repertory;

    private MutableLiveData<WebsiteInfoEntity> websiteInfoEntityLiveData = new MutableLiveData<>(new WebsiteInfoEntity());

    public WebsiteMyXiXinModel(WebsiteMyXiXinActivity websiteMyXiXinActivity, ManageRepertory repertory) {
        this.repertory = repertory;
        this.websiteMyXiXinActivity = websiteMyXiXinActivity;
    }

    public MutableLiveData<WebsiteInfoEntity> getWebsiteInfoData() {
        return websiteInfoEntityLiveData;
    }

    public void getWebsiteInfo(Activity myActivity, String siteNo,String siteType) {
        DialogHelper.showProgressDialog(myActivity, null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        Map<String, String> map = new HashMap();
        map.put("siteNo", siteNo);
        map.put("siteType", siteType + "");
        APIManager.getInstance().getWebsiteInfoAPI().getSiteInfo(map).enqueue(new ICallBack<BaseEntity<WebsiteInfoEntity>>() {
            @Override
            public void onSuccess(BaseEntity<WebsiteInfoEntity> data) {
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    getWebsiteInfoData().postValue(data.getData());
                }
            }
        });
    }
}
